package com.hmall.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmall.ai.AiModelInvoker;
import com.hmall.domain.po.Datas;
import com.hmall.domain.po.Datas2;
import com.hmall.domain.vo.DataVO;
import com.hmall.mapper.DataMapper;
import com.hmall.service.IDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HBQ
 * @since 2025-10-22
 */
@RestController
@RequestMapping("/data")
@RequiredArgsConstructor

public class DataController {

    private final IDataService dataService;
    private final DataMapper dataMapper;

    @PostMapping
    @ApiOperation("上传数据")
    public DataVO commitData(@RequestBody Datas datas) throws IOException {
        DataVO datas1 = dataService.uploadData(datas);
        return datas1;
    }

    @GetMapping("/list")
    @ApiOperation("分页列表查询数据")
    public Page<Datas2> getData(@RequestParam Integer pageNum){

        return dataService.pageQuery(pageNum);
    }
    @GetMapping("/{id}")
    @ApiOperation("通过ID获取数据")
    public Datas getDataById(@PathVariable Long id){
        return dataMapper.selectById(id);
    }

    @GetMapping("/answer")
    @ApiOperation("获取答案")
    public String getAnswer(@RequestParam String mbti, @RequestParam String hobby, @RequestParam String xingzuo){
        return dataService.answerQuestion(mbti, hobby, xingzuo);
    }
}
